<?php

namespace App\Models\Api;

use App\Models\Common\CollOption;
use App\Models\Common\CollTwoOption;

class ResumeLanguageSkill extends ApiModel
{
    //表名
    protected $table = 'resume_language_skill';

    const CREATED_AT = 'addtime';
    const UPDATED_AT = 'updatetime';

    protected $guarded = [];

    /**
     * 追加到模型数组表单的访问器,需要时自行使用append(),查询结束后使用
     *
     * @var array
     */
    protected $appends = ['language_name', 'level_name'];

    /**
     * The attributes that should be hidden for arrays.
     * 隐藏字段
     * @var array
     */
    protected $hidden = ['addtime', 'updatetime', 'uid', 'resume_id'];

    /**
     * 要触发的所有关联关系(子类增删改更新父类updatetime)
     *
     * @var array
     */
    protected $touches = ['resume'];

    /**
     * 技能所属简历
     */
    public function resume()
    {
        return $this->belongsTo(Resume::class, 'resume_id', 'id');
    }

    /** 语言名
     * @return mixed
     */
    public function getLanguageNameAttribute()
    {
        return CollOption::getOptionName($this->attributes['language'], 'language');
    }

    public function getLevelNameAttribute()
    {
        $l = $this->attributes['level'];

        if ($l == 0) {
            return '';
        }
        return CollTwoOption::getTwoOptionName($l, 'language');
    }
}
